package edu.vista;

import java.io.IOException;

import com.sun.lwuit.Dialog;
import com.sun.lwuit.Display;
import com.sun.lwuit.Graphics;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.plaf.Border;

import edu.logica.util.CentralDatos;

public class Loader extends Dialog implements Runnable {

	private Thread hilo;

	public Loader() {
		
		getDialogStyle().setBorder(Border.createRoundBorder(6, 6, 0xe3ef5a));
		setTransitionInAnimator(CommonTransitions.createSlide(
				CommonTransitions.SLIDE_VERTICAL, true, 600));
		setTransitionOutAnimator(CommonTransitions.createSlide(
				CommonTransitions.SLIDE_VERTICAL, false, 600));
		addComponent(new Label(CentralDatos.loader));
		try {
			addComponent(new Animator(Image.createImage("/wait-circle.png")));
		} catch (IOException e) {
			e.printStackTrace();
		}
		int height = Display.getInstance().getDisplayHeight()
				- (getContentPane().getPreferredH() + getTitleComponent()
						.getPreferredH());
		height /= 2;
		show(height, height, 20, 20, true, false);
		hilo = new Thread(this);
		hilo.start();
		// repaint();
		// showModeless();
	}
//	public Loader(boolean vacio){
//		hilo = new Thread(this);
//		hilo.start();
//	}

	public void run() {
		while (CentralDatos.buscando) {
			System.out.println("esperandoooo");
			try {
				Thread.sleep(300);

			} catch (InterruptedException e) {
//				Dialogo.getDialogo().mostrarDialogoInformacion(
//						"error mientras duerme el hilo: " + e.toString());
			}

		}
		//XXX podria cerrarse el loader
	}

	public void paint(Graphics g) {
		super.paint(g);

	}

}
